<template>
	<view>
		<view class="tabs">
			<u-tabs :list="tabsList" :current="tabsIndex" @change="change"></u-tabs>
		</view>
		<view class="content-box">
			<!-- 待整改 -->
			<view class="solved" v-if="tabsIndex==0">
				<view class="solved-box" v-for="question in questions" :key="question.id">
					<view>
						<view class="solved-title">
							<text>{{question.activityName}}</text>
							<text>{{question.createTime}}</text>
						</view>
						<view class="solved-cotent">
							<u-cell-group :border=false>
								<u-cell :title="question.targetName" :isLink="true" center
									@click="handleRectify(question.targetName,question.id)"></u-cell>
							</u-cell-group>
						</view>
					</view>
				</view>
			</view>
			<!-- 待复查 -->
			<view class="pending" v-if="tabsIndex==1">
				<view class="solved-box" v-for="pending in pendings" :key="pending.id">
					<view>
						<view class="solved-title">
							<text>{{pending.activityName}}</text>
							<text>{{pending.createTime}}</text>
						</view>
						<view class="solved-cotent">
							<u-cell-group :border=false>
								<u-cell :title="pending.targetName" :isLink="true" center
									@click="handlePending(pending.targetName,pending.id)"></u-cell>
							</u-cell-group>
						</view>
					</view>
				</view>
			</view>

			<!-- 已销账 -->
			<view class="pended" v-if="tabsIndex==2">
				<view class="solved-box" v-for="imroved in imroveds" :key="imroved.id">
					<view>
						<view class="solved-title">
							<text>{{imroved.activityName}}</text>
							<text>{{imroved.createTime}}</text>
						</view>
						<view class="solved-cotent">
							<u-cell-group :border=false>
								<u-cell :title="imroved.targetName" :isLink="true" center
									@click="handleImroved(imroved.targetName,imroved.id)"></u-cell>
							</u-cell-group>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		schoolQuestion,
		pending,
		imroved
	} from "@/api/school/index.js"
	export default {
		data() {
			return {
				tabsIndex: 0, // 控制tabs的index
				tabsList: [{
					name: '待整改',
				}, {
					name: '待复查',
				}, {
					name: '已销账'
				}],
				questions: [],
				pendings: [],
				imroveds: []
			}
		},
		computed: {
			schoolId() {
				return this.$store.state.user.schoolId
			}
		},
		methods: {
			change(item) {
				this.tabsIndex = item.index
				if (item.index == 0) {
					this.getSchoolQuestion()
				} else if (item.index == 1) {
					this.getPending()
				} else if (item.index == 2) {
					this.getImroved()
				}
			},
			// 待整改
			getSchoolQuestion() {
				schoolQuestion(this.schoolId).then(res => {
					console.log(res)
					this.questions = res.comments
				})
			},
			handleRectify(targetName, id) {
				this.$tab.navigateTo("/pages/school-work/school-rectify/school-rectify-content?targetName=" + targetName +
					"&id=" + id);
			},

			// 待复查
			getPending() {
				pending(this.schoolId).then(res => {
					console.log(res)
					this.pendings = res.comments
				})
			},
			// 待复查详情页面
			handlePending(targetName, id) {
				this.$tab.navigateTo("/pages/school-work/school-rectify/review-school-rectify-content?targetName=" +
					targetName +
					"&id=" + id);
			},

			// 已销账
			getImroved() {
				imroved(this.schoolId).then(res => {
					this.imroveds = res.comments
					console.log(res)
				})
			},
			handleImroved(targetName, id) {
				console.log("进来了")
				this.$tab.navigateTo("/pages/school-work/school-rectify/finished-school-rectify?targetName=" + targetName +
					"&id=" + id);
			}
		},
		onLoad: function() {
			this.getSchoolQuestion()
		}
	}
</script>

<style lang="scss" scoped>
	.tabs {
		display: flex;
		justify-content: center;
		align-items: center;
	}


	.solved-title {
		padding: 0 15px;
		display: flex;
		justify-content: space-between;
	}
</style>